package chixing.day14.work.d4;

import java.util.*;

public class BrowseRecord {
    private String userId;
    private String actionType;
    public BrowseRecord(String userId, String actionType)
    {
        this.userId = userId;
        this.actionType = actionType;
    }
    public BrowseRecord() {
    }

    public String getActionType() {
        return actionType;
    }

    public void setActionType(String actionType) {
        this.actionType = actionType;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    @Override
    public String toString() {
        return "BrowseRecord{" +
                "userId=" + userId +
                ", actionType='" + actionType + '\'' +
                '}';
    }
    public static void main(String[] args) {
        BrowseRecord r1 = new BrowseRecord ("101","浏览商品");
        BrowseRecord r2 = new BrowseRecord ("101","搜索关键字");
        BrowseRecord r3 = new BrowseRecord ("101","添加购物车");
        BrowseRecord r4 = new BrowseRecord ("102","浏览商品");
        BrowseRecord r5 = new BrowseRecord ("102","点赞操作");
        BrowseRecord r6 = new BrowseRecord ("102","收藏操作");
        BrowseRecord r7 = new BrowseRecord ("103","浏览商品");
        BrowseRecord r8 = new BrowseRecord ("103","添加购物车");
        BrowseRecord r9 = new BrowseRecord ("101","浏览商品");
    List list = new ArrayList<>();
    list.add(r1);
    list.add(r2);
    list.add(r3);
    list.add(r4);
    list.add(r5);
    list.add(r6);
    list.add(r7);
    list.add(r8);
    list.add(r9);
        Map<String, Set<String>> map = calculateUserAction(list);
        for (Map.Entry<String, Set<String>> entry : map.entrySet()) {
            System.out.println(entry.getKey() + ": " + entry.getValue());
        }
    }
    public static Map<String, Set<String>> calculateUserAction(List<BrowseRecord> recordList){
        Map<String, Set<String>> userActionMap = new HashMap<>();
        for (BrowseRecord record : recordList) {
            String userId = record.getUserId();
            String actionType = record.getActionType();
            if (!userActionMap.containsKey(userId)) {
                userActionMap.put(userId, new HashSet<>());
            }
            userActionMap.get(userId).add(actionType);
        }
        return userActionMap;
    }
}
